package com.collect.service.impl;


import com.collect.config.StorageProperties;
import com.collect.pojo.CollectDTO;
import com.collect.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @Classname CollectServiceImpl
 * @Description TODO
 * @Date 2025/3/10 10:02
 * @Created by xxx
 */
@Service
public class CollectServiceImpl implements CollectService {

    @Autowired
    private StorageProperties storageProperties;

    @Override
    public void collect_doc(CollectDTO collectDTO) throws IOException {
        String fileName = collectDTO.getFileName();
        MultipartFile file = collectDTO.getFile();
        String type = collectDTO.getType();
        Path path = Paths.get(storageProperties.getPath());
        Path savePath = Paths.get(path.toString(), type, fileName);
        Files.createDirectories(savePath.getParent());
        file.transferTo(savePath.toFile());
    }
}
